package presentation;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import controleur.GestionProduit;

public class FenetreNouveau extends JFrame implements ActionListener {

	private JTextField txtPrixHT;
	private JTextField txtNom;
	private JTextField txtQte;
	private JButton btValider;
	private GestionProduit gp;

	public FenetreNouveau(GestionProduit g) {

		gp = g;
		setTitle("Creation");
		setBounds(500, 500, 200, 210);
		Container contentPane = getContentPane();
		contentPane.setLayout(new FlowLayout());

		JLabel labNom = new JLabel("Nom produit");
		JLabel labPrixHT = new JLabel("Prix Hors Taxe");
		JLabel labQte = new JLabel("Quantité en stock");
		contentPane.add(labNom);
		txtNom = new JTextField(15);
		contentPane.add(txtNom);
		contentPane.add(labPrixHT);
		txtPrixHT = new JTextField(15);
		contentPane.add(txtPrixHT);
		contentPane.add(labQte);
		txtQte = new JTextField(15);
		contentPane.add(txtQte);

		btValider = new JButton("Valider");
		contentPane.add(btValider);

		btValider.addActionListener(this);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btValider) {
			if (!gp.creerProduit(txtNom.getText(),
								Float.valueOf (txtPrixHT.getText()),
								Integer.valueOf(txtQte.getText()))) {
				JOptionPane.showMessageDialog(rootPane, "Le produit existe déjà !");
			}
		}
		this.dispose ();
	}
}